package com.audaque.jadmin.system.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import com.audaque.jadmin.common.utils.EncryptUtil;

/**
 * @Description :密码验证
 * @FileName: CustomCredentialsMatcher.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年10月19日 下午6:49:20
 * @Version:V1.00
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

	@Override
	public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
		UsernamePasswordCaptchaToken token = (UsernamePasswordCaptchaToken) authcToken;

		// 将传进来密码加密方法
		Object tokenCredentials = EncryptUtil.encrypt(String.valueOf(token.getPassword()));
		Object accountCredentials = getCredentials(info);
		// 将密码加密与系统加密后的密码校验，内容一致就返回true,不一致就返回false
		return equals(tokenCredentials, accountCredentials);
	}

}
